package ynu.edu.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import jakarta.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 食品实体类
 */
@Entity
@Table(name = "food")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Food implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 食品编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "foodId")
    private Integer foodId;
    
    /**
     * 食品名称
     */
    @Column(name = "foodName", nullable = false)
    private String foodName;
    
    /**
     * 食品介绍
     */
    @Column(name = "foodExplain")
    private String foodExplain;
    
    /**
     * 食品图片
     */
    @Column(name = "foodImg", columnDefinition = "LONGTEXT")
    private String foodImg;
    
    /**
     * 食品价格
     */
    @Column(name = "foodPrice", nullable = false)
    private BigDecimal foodPrice;
    
    /**
     * 所属商家编号
     */
    @Column(name = "businessId", nullable = false)
    private Integer businessId;
    
    /**
     * 食品分类ID
     */
    @Column(name = "categoryId")
    private Integer categoryId;
    
    /**
     * 备注
     */
    @Column(name = "remarks")
    private String remarks;
    
    /**
     * 创建时间
     */
    @Column(name = "createTime")
    private LocalDateTime createTime;
    
    /**
     * 更新时间
     */
    @Column(name = "updateTime")
    private LocalDateTime updateTime;
    
    /**
     * 数据插入前处理
     */
    @PrePersist
    public void prePersist() {
        if (this.createTime == null) {
            this.createTime = LocalDateTime.now();
        }
        if (this.updateTime == null) {
            this.updateTime = LocalDateTime.now();
        }
    }
    
    /**
     * 数据更新前处理
     */
    @PreUpdate
    public void preUpdate() {
        this.updateTime = LocalDateTime.now();
    }
} 